package cn.cxq.learning.stack;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 * 腾讯校招题：逛该
 * 6
 * 5 3 8 3 2 5
 *
 * [3, 3, 5, 4, 4, 4]
 */
public class Hanging {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] arr = new int[n];
        int[] res = new int[n];
        Arrays.fill(res, 1);

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        Stack<Integer> L = new Stack<>();

        for (int i = 0; i < n; i++) {
            res[i] += L.size();
            if (!L.empty()) {
                while (!L.empty() && L.peek() < arr[i]) {
                    L.pop();
                }
            }

            L.push(arr[i]);
        }

        Stack<Integer> R = new Stack<>();

        for (int i = n - 1; i >= 0; i--) {
            res[i] += R.size();
            if (!L.empty()) {
                while (!R.empty() && R.peek() < arr[i]) {
                    R.pop();
                }
            }

            R.push(arr[i]);
        }

        System.out.println(Arrays.toString(res));
    }
}
